var t = getApp();

Page({
    data: {
        server: t.server,
        serverUrl: t.serverUrl,
        lv1s: [],
        currLv1: 0
    },
    onLoad: function(t) {
        this.loadLv1s(), this.loadMem();
    },
    loadMem: function() {
        var e = this;
        t.request({
            url: t.server + "/userApi/getFactoryInfo",
            method: "POST",
            data: {
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                e.setData({
                    icon: t.data.result.info.icon
                });
            }
        });
    },
    loadLv1s: function() {
        var e = this;
        t.request({
            url: t.rserver + "/videoApi/getCategory",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                e.setData({
                    lv1s: t.data.result.data || []
                }), e.active(0);
            }
        });
    },
    loadLv2s: function(e) {
        var a = this;
        this.data.lv1s[e];
        t.request({
            url: t.rserver + "/videoApi/getCategory",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1,
                parent_id: this.data.lv1s[e].id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var n = {};
                n["lv1s[" + e + "].lv2s"] = t.data.result.data || [], a.setData(n);
                for (var r = 0; r < t.data.result.data.length; r++) a.loadList(e, r);
            }
        });
    },
    loadList: function(e, a) {
        var n = this.data.lv1s[e].lv2s[a], r = this;
        t.request({
            url: t.server + "/videoApi/getVideoCategoryInfo",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1,
                cid: n.id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var n = {}, i = t.data.result.data || [], o = !0, s = !1, d = void 0;
                try {
                    for (var c, u = i[Symbol.iterator](); !(o = (c = u.next()).done); o = !0) {
                        var l = c.value;
                        l.share_icon || (l.share_icon = "/static/albums/album-icon.png"), l.share_content || (l.share_content = "新款发布"), 
                        l.durationTxt = r.fmt(l.duration);
                    }
                } catch (t) {
                    s = !0, d = t;
                } finally {
                    try {
                        !o && u.return && u.return();
                    } finally {
                        if (s) throw d;
                    }
                }
                n["lv1s[" + e + "].lv2s[" + a + "].prds"] = i, r.setData(n);
            }
        });
    },
    fmt: function(t) {
        if (t = parseInt(t), !isNaN(t) && t || (t = 0), !t) return "00:00";
        for (var e = [], a = 3; a > 0; a--) {
            var n = t % 60;
            if (e.splice(0, 0, n > 10 ? n : "0" + n), 0 === (t = parseInt(t / 60)) && a <= 2) break;
        }
        return e.join(":");
    },
    active: function(t) {
        var e = this.data.lv1s[t];
        e.inited || (e.inited = !0, this.loadLv2s(t)), this.setData({
            currLv1: t
        });
    },
    swichCate: function(t) {
        this.active(t.currentTarget.dataset.index);
    },
    switchTab: function(t) {
        this.active(t.detail.current);
    },
    detail: function(t) {
        var e = t.currentTarget.dataset.cate, a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/video/detail/detail?id=" + a + "&lv2Id=" + e
        });
    },
    onReady: function() {},
    onShow: function() {
        wx.setNavigationBarTitle({
            title: "视频"
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});